<template>
  <div class="wrapper clearfix" v-wechat-title="title">
    <van-form @submit="onSubmit">
      <div class="title">基本信息</div>
      <company-dianpuInfo :dataL="dataL"></company-dianpuInfo>
      <div class="title">联系方式</div>
      <company-contact :dataL="dataL"></company-contact>
      <van-button round block type="info" native-type="submit" class="action">
        发布
      </van-button>
    </van-form>
  </div>
</template>

<script>
import CompanyDianpuInfo from './components/CompanyDianpuInfo'
import CompanyContact from './components/CompanyContact'
export default {
  name: 'wanted',
  components: {
    CompanyDianpuInfo,
    CompanyContact
  },
  data () {
    return {
      title: '快速找铺',
      dataL: {}
    }
  },
  mounted () {
    let that = this
    if (that.$route.params.id !== 0) {
      that.$axios.post(process.env.API_HOST + '/api/release/store_detail', {
        id: that.$route.params.id
      }).then(function (res) {
        if (res.data.code === 1) {
          that.dataL = res.data.data
        }
      })
        .catch(error => console.log(error))
    }
  },
  methods: {
    onSubmit (values) {
      if (this.$route.params.id !== 0) {
        values['id'] = this.$route.params.id
      }
      values['store_province'] = sessionStorage.getItem('Dcity')
      values['store_content'] = ''
      delete values['undefined']
      this.$axios.post(process.env.API_HOST + '/api/release/wanted', values
      ).then(this.onSubmitSee)
        .catch(error => console.log(error))
    },
    onSubmitSee (res) {
      let that = this
      if (res.data.code === 1) {
        this.$toast('发布成功')
        setTimeout(function () {
          that.$router.push('/Mrelease/1')
        }, 1500)
      }
    }
  }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="stylus" scoped>
.wrapper
  width 100%
  padding .4rem /* 20/50 */
  padding-top .1rem /* 5/50 */
  .title
    width 100%
    height 1.2rem /* 60/50 */
    line-height 1.2rem /* 60/50 */
    font-size .4rem /* 20/50 */
    font-weight bold
  .van-button
    background-color #F8F8F8
    color #999999
    font-size .4rem /* 20/50 */
    border-radius .1rem /* 5/50 */
    border 0px
    margin-top .8rem /* 40/50 */
  .action
    color #fff
    background linear-gradient(90deg, #F14510, #EE340F)
    box-shadow 1px 1px 5px 0px rgba(255, 1, 1, 0.42)
</style>
